package com.tzg157.fitness.controller;

import cn.hutool.json.JSONUtil;
import com.tzg157.fitness.entity.R;
import com.tzg157.fitness.service.RecommenderServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/recommender")
public class RecommenderController {

    @Resource
    private RecommenderServiceImpl recommenderService;

    @GetMapping("/alsRecommender")
    public R<List<Long>> collaborativeFiltering(@RequestParam("userId")Long userId, @RequestParam("courseId") Long courseId){
        List<Long> retIds = recommenderService.getRecommenderData(userId,courseId);
        return R.ok(retIds);
    }

    @RequestMapping("/randomForest")
    public R<Map<String,Number>> randomForestRecommender(@RequestBody String data){
        Map<String,Object> orgData = JSONUtil.toBean(data, Map.class);
        Map<String,Number> personData = new HashMap<>();
        personData.put("age",Integer.valueOf(orgData.get("age").toString()));
        personData.put("gender",Integer.valueOf(orgData.get("gender").toString()));
        personData.put("weight",Double.valueOf(orgData.get("weight").toString()));
        personData.put("height",Double.valueOf(orgData.get("height").toString()));
        personData.put("experience_level",Integer.valueOf(orgData.get("experience_level").toString()));
        Map<String,Number> retMap = recommenderService.getPlanRecommenderData(personData);
        return R.ok(retMap);
    }


}
